<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['site']=core_setting('site');
$operating=core_setting('operating');
$return['operating']=$operating;
$types=get_permission_types('id','all');
$tabs=array();
foreach($types as $row){
	$tabs[]=array('op'=>'list','query'=>'type='.$row['id'],'title'=>$row['title'],'type'=>$row['id']);
}
unset($tabs[0]);
if($_RQ['op']=='list'){
	$type=$_RQ['type']?intval($_RQ['type']):1;
	$group_id=intval($_RQ['group_id']);
	$style=intval($_RQ['style']);
	$return['params']['type']=$type;
	$return['params']['group_id']=$group_id;
	$return['params']['style']=$style;
	$return['params']['hide']=0;
	if(in_array($type,array('2','3','5'))){
		//手机站模版、pc站模版、小程序模版
		$params=array('uniacid'=>0,'hide'=>0);
	}else{
		$params=array('hide'=>0);
	}
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	
	$fields=array('id','title','price','days','image','tuijie','hdps','paixu');
	if(in_array($type,array('2','3','5'))){
		$fields[]='group_id';
		$fields[]='salenum';
		if($_RQ['group_id']){
			$params['group_id']=$group_id;
		}
	}
	if($type==1){
		//插件功能
		$fields[]='oneword';
		$fields[]='salenum';
		if($_RQ['style']){
			$params['style']=$style;
		}
	}
	$orderby='`paixu` desc, `tuijie` desc ,`price` desc, `id` desc';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 25;
	$total='';
	$list=pdo_getslice($types[$type]['table'],$params,array($pindex,$psize),$total,$fields,'',$orderby);
	if($list){
		$group_actions=pdo_getcolumn('core_account_group',array('id'=>$_SESSION['account']['groupid']),$types[$type]['name']);
		foreach($list as &$row){
			$row['oldprice']=$row['price']>0?price($row['price']*1.6):'108.00';
			if($row['price']<1){
				$row['time']='免费';
			}elseif(strexists($group_actions,';'.$row['id'].';')){
				$row['time']='套餐内置';
			}else{
				$row['buy']=1;
				$time=pdo_getcolumn('core_account_permissions',array('uniacid'=>$_SESSION['uniacid'],'type'=>$type,'pid'=>$row['id']),'time');
				if(!$time){
					$row['time']="{$row['price']}元/{$row['days']}天 待购买";
					$row['buy_action']=array('op'=>'buy','query'=>'type='.$type.'&id='.$row['id'],'title'=>'购买应用');
				}elseif($time<=TIMESTAMP){
					$row['time']='已过期';
					$row['buy_action']=array('op'=>'buy','query'=>'type='.$type.'&id='.$row['id'],'title'=>'购买应用');
				}else{
					$row['time']='有效期至：'.date('20y/m/d',$time);
					$row['buy_action']=array('op'=>'buy','query'=>'type='.$type.'&id='.$row['id'],'title'=>'续费应用');
				}
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['groups']=pdo_getall('core_template_group',array(),array('id','title'));
	if($type==1){
		$return['groups']=get_plugin_styles();
	}
	/*$return['htmls']=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('type'=>'string','name'=>'title','title'=>'应用名称'),
			array('type'=>'string','name'=>'image','title'=>'图片'),
			array('type'=>'string','name'=>'price','title'=>'应用价格'),
			array('type'=>'string','name'=>'days','title'=>'价格周期'),
			array('type'=>'string','name'=>'title','title'=>'应用状态'),
		),'action'=>array(
			array('type'=>'href','name'=>'buy_action','show'=>array('buy',1)),
		)),
		'search_one'=>array('name'=>'title'),
	);*/
	$return['type'] =$type;
	$return['tabs']=$tabs;
	set_html('header','common/header-cms');
	set_html('title','扩展功能');
	exi($return);
}
?>